package com.usian.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.usian.entity.Course;
import com.usian.entity.CourseDTO;
import com.usian.mapper.CourseMapper;
import com.usian.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 陈宇轩
 * @version 1.0
 * @date 2023/8/23 21:13
 */

@Service
public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> implements CourseService {
    @Autowired
    private CourseMapper comMapper;
    @Override
    public Integer findAllCourse() {
        return comMapper.findAllCourse();
    }

    @Override
    public List<Course> syCou() {
        return comMapper.syCou();
    }

    @Override
    public List<Course> syCou1() {
        return comMapper.syCou1();
    }

    @Override
    public List<Course> findAll(CourseDTO courseDTO) {
        LambdaQueryWrapper<Course> queryWrapper = new LambdaQueryWrapper<>();
        if (courseDTO.getLid()!=null&&courseDTO.getLid()!=""){
        queryWrapper.eq(Course::getLid,courseDTO.getLid());
        }
        if (courseDTO.getStatus()!=null){
            queryWrapper.eq(Course::getStatus,courseDTO.getStatus());
        }
        if (courseDTO.getName()!=null&&courseDTO.getName()!=""){
            queryWrapper.eq(Course::getName,courseDTO.getName());
        }
        if (courseDTO.getAa()!=null&&courseDTO.getAa()==1){
            queryWrapper.orderByDesc(Course::getId,Course::getId);

            List<Course> list = comMapper.selectList(queryWrapper);
           return list;
        }
        if (courseDTO.getAa()!=null&&courseDTO.getAa()==2){
            queryWrapper.orderByDesc(Course::getDz,Course::getDz);

            List<Course> list1 = comMapper.selectList(queryWrapper);
            return list1;
        }else {
            List<Course> list2 = comMapper.selectList(queryWrapper);
            return list2;
        }
    }
}
